import {
  Directive,
  ElementRef,
  Input,
  Output,
  EventEmitter,
  AfterContentInit
} from '@angular/core';


@Directive({
  selector: '[appScrollTop]'
})
export class ScrollTopDirective implements AfterContentInit {
  @Input('appScrollTop') sign: any;
  @Output() scrollTop: EventEmitter<any> = new EventEmitter();

  constructor(private el: ElementRef) {
  }

  // 获取列表文档区间
  ngAfterContentInit() {
    const height = this.el.nativeElement.offsetHeight;
    const start = this.el.nativeElement.offsetTop;
    this.scrollTop.emit({
      start,
      end: start + height,
      sign: this.sign
    });
  }
}
